from flask import Blueprint, request
from utilsapp.mysql_con import db_pagelist, db_connect, db_delete, db_table_pagelist, db_update,db_insert
from utilsapp.common import assign_value, parsing_data_id
from utilsapp import utils
import json

bluePrint = Blueprint('bearing', __name__)
tableName = 'bearing'

@bluePrint.route('/getlist', methods=['POST'])
def table_list():
    if 'page' in request.json.keys() and 'size' in request.json.keys():
        page = request.json['page']
        size = request.json['size']
    else:
        page = 1
        size = 999
    j = db_table_pagelist(tableName, page, '', size)
    return j



@bluePrint.route('/add', methods=['POST'])
def project_add():
    return db_insert(tableName, request.json)



@bluePrint.route("/edit", methods=['post'])
def b():
    id_ = assign_value(request.json, "id")
    return db_update(tableName,request.json,f"where id =%s", {"id_": id_})

@bluePrint.route('/delete', methods=["post"])
def table_delete():
    id = request.json['id']
    return db_delete(tableName, f'WHERE id=%s', {'id': id})
